package com.zb.controller;

import io.modelcontextprotocol.client.McpSyncClient;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderChatController {


    private final List<McpSyncClient> mcpSyncClients;
    private final ChatClient chatClient;

    public OrderChatController(List<McpSyncClient> mcpSyncClients,ChatClient.Builder chatClient) {
        this.mcpSyncClients = mcpSyncClients;
        this.chatClient = chatClient.build();
    }

    @RequestMapping("/chat")
    public String chat(@RequestParam(defaultValue = "ORDER20250903-0001",required = false,name = "question") String question) {
        return chatClient.prompt("你是xx商城的智能助手，可以快速帮助用户提供订单查询服务，需要接收用户的订单编号，然后查询出对应的订单信息交给用户；")
                .user(question)
                .toolCallbacks(SyncMcpToolCallbackProvider.syncToolCallbacks(mcpSyncClients))
                .call()
                .content();
    }

}
